#include<bits/stdc++.h>
using namespace std;
int d[100010],v[100010],a[100010],p[100010];
int ans=0;
int main(){



    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);





    int t;
    cin>>t;
    while(t--){
        ans=0;
        int n,m,L,V;
        cin>>n>>m>>L>>V;
        for(int i=1;i<=n;i++){
            cin>>d[i]>>v[i]>>a[i];
            if(a[i]==0&&v[i]<=V) d[i]=0x3f3f3f3f;
        }
        for(int i=1;i<=m;i++){
            cin>>p[i];
        }
        for(int i=1;i<=n;i++){
            if(d[i]<=p[m]){
                ans++;
            }
        }
        if(ans==0){
            cout<<ans<<" "<<m<<endl;
        }
        else cout<<ans<<" "<<m-1<<endl;
    }
    return 0;
}
